package com.eastedu.repository.ktree.po;

import com.baomidou.mybatisplus.annotation.*;
import com.eastedu.entity.jdbc.BaseEntity;
import jakarta.persistence.Column;
import lombok.Data;
import org.hibernate.Hibernate;

import java.util.Objects;

/**
 * 知识树节点
 *
 * @author luozhenzhong
 */
@Data
@TableName(value = "t_knowledge_node")
public class KnowledgeNodePO extends BaseEntity<KnowledgeNodePO> {
    /**
     * 树结构根节点ID
     */
    @Column(name = "root_id", nullable = false, columnDefinition = "bigint(11) COMMENT '树结构根节点ID'")
    private Long rootId;

    /**
     * 全局唯一标识符
     */
    @Column(name = "guid", nullable = false, columnDefinition = "varchar(36) COMMENT '全局唯一标识符'")
    private String guid;

    /**
     * 知识节点名称
     */
    @Column(name = "name", nullable = false, columnDefinition = "varchar(200) COMMENT '知识节点名称'")
    private String name;

    /**
     * 树层级
     */
    @Column(name = "level", nullable = false, columnDefinition = "int COMMENT '树层级'")
    private Integer level;

    /**
     * 备注
     */
    @Column(name = "remark", columnDefinition = "varchar(500) COMMENT '备注'")
    private String remark;

    /**
     * 顺序
     */
    @Column(name = "`order`", nullable = false, columnDefinition = "int COMMENT '顺序'")
    @TableField("`order`")
    private Integer order;

    /**
     * 创建用户ID
     */
    @Column(name = "create_user_id", nullable = false, columnDefinition = "bigint(20) COMMENT '创建用户ID'")
    private Long createUserId;


    /**
     * 序列号
     */
    @Column(name = "serial_number", columnDefinition = "varchar(200) COMMENT '序列号'")
    private String serialNumber;

    /**
     * 是否可用
     */
    @TableLogic(value = "1", delval = "0")
    @TableField(value = "available", fill = FieldFill.INSERT)
    @Column(name = "available", nullable = false, columnDefinition = "bit default 1 COMMENT '是否可用'")
    private Boolean available;

    @Version
    @Column(name = "`version`", nullable = false, columnDefinition = "int default 0 COMMENT '版本号'")
    private Integer version;


    @Column(name = "freeze", nullable = false, columnDefinition = "bit(1) DEFAULT b'0' COMMENT '是否冻结'")
    private Boolean freeze;

    /**
     * 第三方编号
     */
    @Column(name = "third_number", columnDefinition = "text COMMENT '第三方编号'")
    private String thirdNumber;

    @Column(name = "definition_json", columnDefinition = "json COMMENT '定义'")
    private String definitionJson;

    @Column(name = "knowledge_evaluate_requirement_code", columnDefinition = "varchar(30) COMMENT '知识评价要求编码'")
    private String knowledgeEvaluateRequirementCode;

    @Column(name = "knowledge_type_json", columnDefinition = "json COMMENT '知识点类型'")
    private String knowledgeTypeJson;

    @Column(name = "knowledge_mark_json", columnDefinition = "json COMMENT '知识点标记'")
    private String knowledgeMarkJson;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
            return false;
        }
        KnowledgeNodePO that = (KnowledgeNodePO) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
